package com.ycy.servlet;

import java.io.IOException;
import java.util.Arrays;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ycy.ss.Constant;
import com.ycy.ss.WriteJob;
import com.ycy.ss.sync.AllType;
import com.ycy.ss.sync.Info;


public class ManualPost extends HttpServlet{
	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
		doPost(req, resp);
	}

	@Override
	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
		String to = req.getParameter("to");
		if (!Arrays.asList(Constant.getSyncAllManualTo()).contains(to)) {
			resp.getWriter().write("manualPost failed,doesn't contains:" + to);
			return;
		}

		String content = req.getParameter("content");
		if (content == null || content.length() == 0) {
			resp.getWriter().write("manualPost failed,content is empty");
			return;
		}
		
		Info info = new Info();
		info.setFromSite("manual");
		info.setType(AllType.TEXT);
		info.setContent(new String(content.getBytes("ISO-8859-1"),"UTF-8"));
		WriteJob.QUEUE_LIST.add(info);

		resp.getWriter().write("manualPost success.");
	}
}
